package com.spring.lo.framework.core.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * ClassPath资源对象
 * @author zhangbh
 * 2023-05-28 14:34
 **/
public class ClassPathResource implements Resource {

    private final String location;

    public ClassPathResource(String location) {
        this.location = location;
    }

    @Override
    public InputStream getInputStream() throws IOException {
        String location = this.location;
        // 提前处理 web环境下 classPath的特殊格式
        if (location.startsWith("classpath:")) {
            location = location.replace("classpath:", "");
        }
        if (location.startsWith("classpath*:")) {
            location = location.replace("classpath*:", "");
        }
        return this.getClass().getClassLoader().getResourceAsStream(location);
    }
}
